import pymongo
import datetime
from pycookiecheat import chrome_cookies

MONGO_URL = "mongodb://47.98.146.210:27017"

def main():

    cookie_taobaolive = chrome_cookies('https://taobaolive.taobao.com/')
    cookie_taobaolive_str = ''
    for k in cookie_taobaolive:
        cookie_taobaolive_str = cookie_taobaolive_str + k + "=" + cookie_taobaolive[k] + "; "
    print(cookie_taobaolive_str)

    cookies = chrome_cookies('https://item.taobao.com/')
    cookie_str = ''
    for k in cookies:
        cookie_str = cookie_str + k + "=" + cookies[k] + "; "

    cookies_1688 = chrome_cookies('https://view.1688.com')
    cookie_str_1688 = ''
    for v in cookies_1688:
        cookie_str_1688 = cookie_str_1688 + v + "=" + cookies_1688[v] + "; "

    cookies_h5 = chrome_cookies('https://h5.m.taobao.com/')
    cookie_str_h5 = ''
    for h in cookies_h5:
        cookie_str_h5 = cookie_str_h5 + h + "=" + cookies_h5[h] + "; "

    cookies_tblive = chrome_cookies('https://tblive.m.taobao.com')
    cookie_str_tblive = ''
    for h in cookies_tblive:
        cookie_str_tblive = cookie_str_tblive + h + "=" + cookies_tblive[h] + "; "

    myclient = pymongo.MongoClient(MONGO_URL)
    mydb = myclient["QK_GOODS"]
    mycol_goods = mydb["qk_cookies"]

    item = {}
    item['qk_taobao'] = cookie_str
    item['cookie_taobaolive'] = cookie_taobaolive_str
    item['qk_taobao_json'] = cookies
    item['qk_1688'] = cookie_str_1688
    item['qk_h5_taobao'] = cookie_str_h5
    item['qk_tblive'] = cookie_str_tblive
    item['time'] = str(datetime.date.today())
    print(item)
    mycol_goods.insert_one(item)
    myclient.close()


if __name__ == '__main__':
    main()
